package org.jeeasy.cloud.gateway;

import com.alibaba.cloud.commons.lang.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * 入 口 启 动 类
 *
 * @author AlpsDDJ
 * @date
 */
@Slf4j
@SpringBootApplication(scanBasePackages = "org.jeeasy")
@EnableDiscoveryClient
// @MapperScan("org.jeeasy.**.mapper")
//@EnableConfigurationProperties({ SwaggerModuleConfiguration.class })
public class JeeasyGatewayApplication extends SpringBootServletInitializer {
    public static void main(String[] args) {
        ConfigurableApplicationContext application = SpringApplication.run(JeeasyGatewayApplication.class, args);
        Environment env = application.getEnvironment();
        try {
            String ip = InetAddress.getLocalHost().getHostAddress();
            String port = env.getProperty("server.port");
            String path = env.getProperty("server.servlet.context-path");
            String appName = env.getProperty("spring.application.name");
            String activeProfile = env.getProperty("spring.profiles.active");

            path = StringUtils.isBlank(path) ? "" : path;

            String appInfo = """
                    \n----------------------------------------------------------
                        Application %s is running!
                        Env: %s
                        Access URLs:
                            Local: 		http://localhost:%s/
                            External: 	http://%s:%s/
                    ----------------------------------------------------------
                    """.formatted(appName, activeProfile, port + path, ip, port + path);
            log.info(appInfo);
        } catch (UnknownHostException e) {
            log.warn(String.valueOf(e));
        }
    }
}
